home *** CD-ROM | disk | FTP | other *** search
/ Language/OS - Multiplatform Resource Library / LANGUAGE OS.iso / cpp_libs / awe2-0_1.lha / awe2-0.1 / Overview.txt < prev   
Text File  |  1990-07-09  |  11KB  |  332 lines

  1. This is the nickle tour of this tasking package.
  2. Mail contact: grunwald@foobar.colorado.edu
  3.  
  4. Content:
  5. ----------
  6.  
  7. Basically, this provides Threads, that are multiplexed on one (or
  8. more) UNIX CPUs. Subclassing provides a simulation environment.
  9.  
  10. History:    
  11. ----------
  12.  
  13. The package name has been Awesime. This is basically rev 2.  Parts of
  14. this (random number generators, statistic, histogram & GenericHeap)
  15. have also been donated to libg++. I expect that the rest of it will be
  16. donated, so it's been copy righted for now, but it will be turned
  17. over.
  18.  
  19. Anyone extending the package or using it should assume that it will
  20. follow the Gnu software copyleft.
  21.  
  22. Right now, this only works with G++.
  23.  
  24. File Layout:
  25. ----------
  26.  
  27.     The Documentation directory contains a very old copy of the
  28.     documentation. This needs serious revision.
  29.  
  30.     Src points to the current source. NewSrc uses Multiple Inheitence
  31.     and OldSrc does not. OldSrc works on the PMAX, NewSrc doesn't work.
  32.     I think that NewSrc is correct, however, I keep running into
  33.     problems with Multiple Inheitence in G++.
  34.  
  35.     Examples contains a couple of simple example programs.
  36.  
  37. GNUmakefile:
  38. ----------
  39.     I use gnumake. The makefile is in Src/GNUmakefile.
  40.     This GNUmakefile includes several others:
  41.     
  42.     GNUmakefile.host    - Configure everything for your host and
  43.                 compilation method (GCC or g++)
  44.  
  45.     GNUmakefile.files    - Automatically generated by ``make files''
  46.                 from Src. Shouldn't be changed, usually.
  47.  
  48.     GNUmakefile.depend    - Automatically generated by ``make depend''
  49.                 from Obj-GCC or Obj-g++
  50.  
  51. What needs to be changed to put it on a new host:
  52. ----------------------------------------------------
  53.     run ``config.awe2 your-host-type'' where host types are
  54.     sun3, umax, onemax, pmax and eventually sun4 and solbourne.
  55.  
  56.     this makes Obj-g++-<hosttype>,  GNUmakefile.host, links in 
  57.     HardwareContext routines (machine specific context switching)
  58.     and a configuration file.
  59.  
  60. For porting to a new machine:
  61. ----------------------------------------------------
  62.  
  63.     You'll need to change HardwareContext.cc, CpuMultiplexor.cc,
  64.     SpinLock-<your-machine>.cc. I think that's it. Maybe the
  65.     SharedMalloc.cc as well.
  66.  
  67.     The basic thread model is that you can share *all* of your data
  68.     and bss and *none* of your per-UNIX stack.
  69.  
  70.  
  71. File by file contents.
  72. ----------------------------------------------------
  73.  
  74. ** This is out of date & does not reflect the multiple inherietence model **
  75.  
  76.     This is only the stuff that doesn't also come with Gnu G++.
  77. You might want to print ``Documentation/hier.tex'' while looking at
  78. this. This contains the class hierarch. Hier.tex is generated by the
  79. Classtree tool. I've left a tar of this on a.cs.uiuc.edu under
  80. directory C++. Don't complain about the tool: it's ugly & slow but I
  81. use it only once in a while, so I didn't care how bad it was.
  82.  
  83. Awesime.cc    - Base class definition. Eventually dispose of this.
  84.  
  85. AwesimeFifo.cc    - An instance of GenericFifo. Has subclasses LockedFifo,
  86.           LowerBoundedFifo, BoundedFifo. Used to keep lists of
  87.           pointers to things.
  88.  
  89. AwesimeHeap.cc    - Like above, but for heaps.
  90.  
  91. Barrier.cc    - Barrier for threads. Uses a SpinLock to lock data.
  92.           Subclass of ReserveByException
  93.  
  94. BoundedFifo.cc    - Subclass of LowerBoundedFifo that has an upper and lower
  95.           on how much stuff it holds. Use for bounded buffers in
  96.           readers/writers
  97.  
  98. Config.h    - Define things for specific machine types
  99.  
  100. CpuMultiplexor.cc
  101.         - The base class for multiplexing Threads.
  102.  
  103. CpuMuxExceptions.cc
  104.         - Exceptions for the CpuMultiplexor class
  105.  
  106. Debug.h        - Some debug assists
  107.  
  108. Defaults.cc    - This is done because we don't have delegation by pointer
  109.           and I want to be able to specify the ``current event''
  110.           data structure at run time.
  111.  
  112. Event.cc    - An event for a Thread. Similar to a barrier; however,
  113.           everyone waits until the event is triggered.
  114.  
  115. ExceptionClass.cc
  116.         - Base class for exceptions. Doesn't do anything.
  117.  
  118. Facility.cc    - Define a facility based on a Semaphore. Tracks utilization
  119.          and queue lengths
  120.  
  121. FifoScheduler.cc
  122.         - A ThreadContainer that has a FIFO discipline
  123.  
  124. Generic.h    - My generic.h -- different than AT&T C++, and geared
  125.           toward cpp-g++
  126.  
  127. GenericFifo.cc    - Generic memory efficient FIFO structure. Used a lot.
  128.         Eventually to be replaced by ``plex'' or something like
  129.         that from libg++
  130.  
  131.  
  132. GenericHeap.cc    - A generic memory efficient pairing heap. Eventually,
  133.         should be replaced by PairingHeap.proto from libg++
  134.         (ParingHeap.proto was derived from this code).
  135.  
  136. HardwareContext-sun3.s
  137.         - The magic stack switching routine for a Sun3. Assumes
  138.         you have a 68881 FPU.
  139.  
  140. HardwareContext-umax.s
  141.         - The magic stack switcher for the Encore. Assumes you
  142.         have an FPU.
  143.  
  144. HardwareContext.cc
  145.         - C++ interface for assembler code. Ideally, the above
  146.         would be inlines.
  147.  
  148. HeapScheduler.cc
  149.         - A ThreadContainer that keeps a heap of ThreadEvents in
  150.         priority order. This is used to by SimulationMultiplexor
  151.  
  152. LockedFifo.cc    - Subclass of AwesimeFifo. Has locks around data access
  153.         to insure exclusive access
  154.  
  155. LowerBoundedFifo.cc
  156.         - Subclass of LockedFifo that insures a Thread can't remove
  157.         things if there's nothing to remove. Uses a semaphore.
  158.  
  159. MonitorSimMux.cc
  160.         - Subclass of SimulationMultiplexor. Has CPU 0 gather
  161.         statistics each time that Time is advanced. Adds cost
  162.         of extra rendezvous at each Time tick, but you can
  163.         see ``degree of parallelism'' possible.
  164.  
  165. ReserveByException.cc
  166.         - Base class for things that may need to be reserved from
  167.         a ``safe context'' (i.e. the CPU context). Subclases
  168.         are Semaphore, Barrier and Event.
  169.  
  170. Semaphore.cc    - Counting semaphore for threads.
  171.  
  172. SharedMalloc-fake.cc
  173.         - If you're not using SharedMemory, you don't want to use
  174.         the extra-overhead malloc. This is a stub.
  175.  
  176. SharedMalloc-real.cc
  177.         - This is a memory allocator (stolen from Choices, actually).
  178.         I need to replace this with something better.
  179.  
  180. SharedMemory-fake.cc
  181.         - If you don't have shared memory, include this stub.
  182.  
  183. SharedMemory-umax.cc
  184.         - But if you're on an Encore, use this. Assumes that
  185.         the variable ``environment'' defines the beginning of
  186.         the data area.
  187.  
  188. SimulationMultiplexor.cc
  189.         - Subclass of CpuMultiplexor. Provides simulated time,
  190.         event list. Subroutine ``hold'' is used to delay thread.
  191.  
  192.  
  193. SpinBarrier.cc
  194. SpinEvent.cc
  195. SpinFetchAndOp.h
  196. SpinLock-fake.cc
  197. SpinLock-umax.s
  198. SpinLock.h
  199.         - All of these are spinlocks of one kind or another.
  200.         SpinLock is a basic SpinLock, and parts are in assembly.
  201.         If I were using G++, I'd make these be inlines with asms
  202.         for the particular instruction that does the test-and-set.
  203.  
  204.         SpinBarrier uses a SpinLock to implement a barrier.
  205.  
  206.         SpinFetchAndOp is a hack to make things like
  207.             lock.reserve(); value++; lock.release()
  208.         faster. It's not very general yet, really only does adds.
  209.         Discard when I get real inlines with asms....
  210.  
  211. Thread.cc
  212.         - The Thread base class. Never create instances of Thread,
  213.         it should always be subclassed.
  214.  
  215. ThreadContainer.cc
  216.         - A thing that contains threads, e.g. HeapScheduler,
  217.         FifoScheduler. One would expect that ReserveByException
  218.         should be a subclass of this. Maybe it should be.
  219.  
  220. ThreadEvent.h
  221.         - An event for a thread. Contains a time and the thread
  222.         to schedule at that time
  223.  
  224. ThreadHeap.cc
  225.         - A heap of threads, orderd on thread priority.
  226.  
  227. assert.cc
  228.         - A version of assert for cpp-g++
  229.  
  230.  
  231.  
  232. How it works:
  233.  
  234. You create a CpuMultiplexor in main(), on the CPU stack. This has room
  235. for a HardwareContext that is ``unchecked'' and has a zero-length stack
  236. allocated (because you're using the system stack).
  237.  
  238. This is refered to as the ``cpu context'', i.e. the context that is really
  239. associated with the UNIX cpu. Things that are in the CpuMultiplexor
  240. structure are per-cpu private. I.e. if you want to pass a value to
  241. another CPU, put it somewhere else. Things like currentThread (the
  242. pointer to the current Thread) and iYam (my CPU number).
  243.  
  244. The global pointer ThisCpu gets filled in by CpuMultiplexor (and any
  245. subclasses) as a pointer to the CpuMultiplexor structure. This is
  246. used when a thread needs to know some information, like ``who am i''
  247. or ``which cpu am I on''?
  248.  
  249. After you create the CpuMultiplexor, you add a bunch of threads to it
  250. (at least one). You then call ``fireItUp'', specifying the number of
  251. CPUs to use, and the additional memory allocate.
  252.  
  253. fireItUp is an interface for three routines: warmThePot, stirItAround and
  254. coolItDown.
  255.  
  256. warmThePot forks the UNIX process, assigns each child a unique id number
  257. (stored in iYam) and calls allocateEventStructures to build data structures.
  258. Both warmThePot and allocateEventStructures are virtualed by subclasses
  259. if they create data structures.
  260.  
  261. stirItAround removes things from the current event list and execute them.
  262. If there's nothing in the `local pile' of event, it will steal form another
  263. CPUs pile.
  264.  
  265. You'll notice that several structures (event lists, various counters, etc)
  266. have pointers defined for them. This is done because the data structures
  267. are statically allocated (in CpuMultiplexor.cc), their names are suppressed
  268. (by `static'), but subclasses need to access them. Gross, but worth it
  269. for the price of saving several indirect array de'refs.
  270.  
  271. This is the big rule that I've observed in tuning this thing: adding anything
  272. to the add-remove-schedule loop is a performance hit, much more than you'd
  273. think likely. 
  274.  
  275. Threads are executed in stirItAround by doing a switchContext on the
  276. current context, passing the value of the new context. They return by
  277. the ``raise'' member, which is called by Threads. You stuff an ExceptionClass
  278. pointer into the CpuMultiplexor and switch to the cpu HardwareContext.
  279. The cpu calls the exception handler for that exception. The exception can
  280. do things like zero out the currentThread (to force a new one to be
  281. fetched), or whatever is needed.
  282.  
  283. One of the exceptions is reserveException. This is for threads and semaphores.
  284. The problem is that if a Thread is being added to a semaphore FIFO,
  285. and you're using the stack of that Thread to do the addition, another
  286. Cpu can come along, remove the thread from the FIFO while you're still
  287. using the threads context. This is a Bad Thing. By having the cpu context
  288. do these reservations, you'll never run into this problem because you're
  289. never supposed to suspend the Cpu context (ha!).
  290.  
  291. stirItAround can get called multiple times, e.g. the simulation system
  292. puts things in the current queue, stirs them around, advances time,
  293. stirs things around, etc etc
  294.  
  295. coolItDown kills waits for all Cpus but Cpu 0 to die.
  296.  
  297.  
  298. Policy for changes:
  299.     + Send changes to me, and I'll redistribute them. Indicate if you're
  300.       going to want to donate it to FSF.
  301.  
  302.     + Let me know if the structure is bad for certain machines, and how
  303.       to fix it. Works for Encore, any uni-processor. Looks like it'll
  304.       work on the Alliant.
  305.  
  306. Needed additions:
  307.     + finish up addCpu and removeCpu to change the number of Cpus on
  308.       the fly
  309.  
  310.     + Use calendar queues instead of pairing heaps
  311.             ** I now use splay heaps
  312.  
  313.     + use G++ standard tools, replacing GenericFifo and GenericHeap
  314.             ** I don't use GenericHeap any more
  315.  
  316.     + port to more machines
  317.  
  318.     + Provide different simulation subclasses. It would be nice to 
  319.       have a set of sub-classes that have the pure event-based
  320.       mechanisms of GPSS.
  321.  
  322.     + provide more classes for simulation mechanisms, i.e. a SimMemory
  323.       class or something. Better statistics on existing measures.
  324.  
  325.     + Convert OwnedFacility (this is like Facility, but each server
  326.        has an owner associated with it to detect reserve/release races)
  327.       to the new revision
  328.  
  329.  
  330.  
  331.  
  332.